#ifndef __RC_ROUTINE_H__
#define __RC_ROUTINE_H__


#define YYREENTRANT_PARAM YYLTYPE * yylloc_param , yyscan_t yyscanner , struct ast** a ,
int _yyerror(YYREENTRANT_PARAM const char* s ,...) __attribute__((format(printf,4,5)));;

#if defined(YYBISON) 
#define yyerror(...) _yyerror( __VA_ARGS__) 
#elif defined(FLEX_SCANNER)
#define yyerror(...) _yyerror(NULL, NULL, NULL , __VA_ARGS__) 
#else
#define yyerror(...) ( fprintf(stderr, __VA_ARGS__) , fprintf(stderr,"\n") )
#endif

enum nodetype {
  /* 低三位预留作为比较符 */
  ntype_gt          = 1,
  ntype_lt          = 2,
  ntype_ne          = 3,
  ntype_eq          = 4,
  ntype_ge          = 5,
  ntype_le          = 6,
  // undefine 0007;
  ntype_or          = 8,
  ntype_nand        = 9,
  ntype_and         = 10,
  ntype_not         = 11,

  ntype_int         = 17,
  ntype_float       , //= 18,
  ntype_fn          , //= 19,
  ntype_name        , //= 20,
  ntype_str         , //= 21,
  ntype_lst         , //= 22,

  ntype_max
};
struct ast {
  int nodetype;
  int pos;
  struct ast* l; // left node
  struct ast* r; // right node
};

struct arglist {
  int nodetype; // ntype_lst
  int pos;
  int cnt; // list node cnt. when cnt=1,n must be NULL
  struct ast* v; // value
  struct arglist* n; // next
};

struct intval {
  int nodetype; /* with 'I' value */
  int pos;
  long val;
};
struct floatval {
  int nodetype; /* with 'F' value */
  int pos;
  double val ;
};
struct strval {
  int nodetype; /* with ntype_name ntype_str value */
  int pos;
  char val[1] ;//__attribute__((bnd_variable_size));
};

struct fncall { // function call
  int nodetype; /* with 'S' value */
  int pos;
  struct ast* n; // func name
  struct ast* l; // args list
};

struct ast* newast(int type , struct ast* l, struct ast* r);
struct ast* newnum(long v);
struct ast* newfloat(double v);
struct ast* newfunc(int functype , struct ast* n,struct ast* l );
struct ast* newlist (struct ast* l );
struct ast* addtolist (struct ast* lst , struct ast* add );
struct ast* newstr(int nodetype, char* v );
const char* gettypename(int type);


#endif //__RC_ROUTINE_H__
